---
title: StateNotifierProvider
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
import CodeBlock from "@theme/CodeBlock";
import todos from "!!raw-loader!/docs/providers/state_notifier_provider/todos.dart";
import todosConsumer from "!!raw-loader!/docs/providers/state_notifier_provider/todos_consumer.dart";
import { trimSnippet } from "../../src/components/CodeSnippet";

`StateNotifierProvider` is a provider that is used to listen to and expose a
[StateNotifier] (from the package [state_notifier], which Riverpod re-exports).

It is typically used for:

- exposing an **immutable** state which can change over time after reacting to
  custom events.
- centralizing the logic for modifying some state (aka "business logic") in a
  single place, improving maintainability over time.

:::info
Prefer using [NotifierProvider] instead.  
:::

As a usage example, we could use `StateNotifierProvider` to implement a todo-list.
Doing so would allow us to expose methods such as `addTodo` to let the UI
modify the list of todos on user interactions:

<CodeBlock>{trimSnippet(todos)}</CodeBlock>

Now that we have defined a `StateNotifierProvider`, we can use it to interact
with the list of todos in our UI:

<CodeBlock>{trimSnippet(todosConsumer)}</CodeBlock>

[state_notifier]: https://pub.dev/packages/state_notifier
[statenotifier]: https://pub.dev/documentation/state_notifier/latest/state_notifier/StateNotifier-class.html
[provider]: ./provider
[futureprovider]: ./future_provider
[notifierprovider]: ./notifier_provider
